package NG::Sys::Cached::Referenced;
use strict;
use warnings;
use utf8;

sub configure {
	my $parent = shift;
	my $realclass = shift;
	unless($parent->{refkey}){
		die "need refkey for referencing";
	}
	unless($parent->{refsub}){
		die "need refsub for referencing";
	}
	unless($parent->{refname}){
		die "need refname for referencing";
	}
	my $app = $parent->{app};
	no strict 'refs';
	*{$realclass."::".$parent->{refsub}} = eval "sub {
		my \$self = shift;
		my \$ref = \$app->reference(\"".$parent->{refname}."\");
		return \$ref->get_by_key(\$self->".$parent->{refkey}.");
	}";
	if($@){
		die $@;
	}
}

1;
